﻿UFTNew_Create = function() {
    var load = $id("load_UFTNew");
    var link = $id("lnkfltr_UFTNew");
    
    if(confirm("save changes?"))
    {
        // di sini kirim data perubahannya
        var input = getUFTData();
        if(input)
        {
            link.style.display = "none";
            load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
            cbkUFTNew_c.PerformCallback(input);
        }
        else
        {
            link.style.display = "block";
            load.innerHTML = "";
        }
    }
}
cbkUFTNew_c_CallbackComplete = function(e) {
    window.location = "UFTNew.aspx?eid=" + e.result;
}
cbkUFTNew_c_CallbackError = function(e) {
    var load = $id("load_UFTNew");
    var link = $id("lnkfltr_UFTNew");
    
    link.style.display = "block";
    load.innerHTML = ""; 
}

DoSelect = function(){
    dgGuest_Invitation_c.PerformCallback("select");
    $id("hfSelect").value = "Y";
}
dgGuest_Invitation_c_EndCallBack = function(e){
    var hf = $id("hfSelect");
    if(hf.value == "Y")
    {
        dgSelected_Invitation_c.PerformCallback("refresh");
    }
    
    hf.value = "";    
}

DoSubmit = function(){
    var load = $id("loadSubmit");
    var link = $id("btnSubmit");
    
    link.style.display = "none";
    load.innerHTML = "<img src='" + LOADING.src + "' alt='' />";
    
    cbkInvitation_c.PerformCallback("");
}
cbkInvitation_c_CallbackComplete = function(e) {
    window.location = "UFTList.aspx?mode=submitted";
}
cbkInvitation_c_CallbackError = function(e) {
    var load = $id("loadSubmit");
    var link = $id("btnSubmit");
    
    link.style.display = "block";
    load.innerHTML = ""; 
}

toggle = function(fsid) {
    var div = $id("div_" + fsid);
    var create = $id("lnkfltr_" + fsid);
    var display = "";

    if (div.style.display != "none") {
        display = "none";
    }
    div.style.display = display;
    
    if(create != null){
        create.style.display = display;
    }
}
FilterTema = function()
{
    var lovhTema = $id("lovh_UFT.FILTERTEMA");
    var eventID = lovhTema.value;
    dgGuest_Invitation_c.PerformCallback("FILTER" + DELIMITER + eventID);
}
All = function()
{
    var lovhTema = $id("lovh_UFT.FILTERTEMA");
    var lovTema = $id("lov_UFT.FILTERTEMA");
    lovhTema.value = "";
    lovTema.value = "";
    dgGuest_Invitation_c.PerformCallback("ALL");
}
getUFTData = function()
{
    var inputs = $nm("txt");
    var output = "";
    var iEmptyValueCount = 0;
    var iNotUploadedCount = 0;
    var iStartHour;
    var iStartMinute;
    var iEndHour;
    var iEndMinute;
    var start = $id("UFT.STARTTIME");
    var end = $id("UFT.ENDTIME");
    for( var i=0; i < inputs.length; i++ )
    {
        if( i > 0 )
        {
            output += DELIMITER;
        }
        
        var item = inputs[i];
        //var lov = $id("lov_" + item.id);
        
        //if( lov == null )
        //{
            if(item.id == "UFT.STARTTIME")
            {
                iStartHour = parseInt(item.value.split(":")[0]);
                iStartMinute = parseInt(item.value.split(":")[1]);
            }
            if(item.id == "UFT.ENDTIME")
            {
                iEndHour = parseInt(item.value.split(":")[0]);
                iEndMinute = parseInt(item.value.split(":")[1]);
            }
            output += item.id + NEWLINE + item.value;
            if(item.value == "")
            {
                iEmptyValueCount++;
                item.style.backgroundColor = "#FFAAAA";
            }
            var uplbtn = $id("uplbtn_" + item.id);
            if(uplbtn != null)
            {
                iNotUploadedCount++;
                item.style.backgroundColor = "#FFAAAA";
            }
        //}
//        else
//        {
//            var lovh = $id("lovh_" + item.id);
//            output += lov.value + NEWLINE + lovh.value + NEWLINE + item.value;        
//        }
    }
    var sxError = "";
    //alert(iStartHour+":"+iStartMinute);
    //alert(iEndHour+":"+iEndMinute);
    if( iNotUploadedCount > 0 )
    {
        sxError += "Terdapat file yang belum diupload! \n\n";
    }
    
    if( iEmptyValueCount > 0 )
    {
        sxError += "Terdapat field isian yang belum diisi! \n\n";
    }
    
    if (iStartHour > iEndHour)
    {
        sxError += " Format waktu salah \n\n";
        start.style.backgroundColor = "#FFAAAA";
        end.style.backgroundColor = "#FFAAAA";
    }
    else if (iStartHour == iEndHour && iStartMinute >= iEndMinute)
    {
        sxError += " Format waktu salah \n\n";
        start.style.backgroundColor = "#FFAAAA";
        end.style.backgroundColor = "#FFAAAA";
    }
    
    if( sxError != "" )
    {
        alert(sxError);
        return false;
    }
    
    return output;
}
SetHours = function(operand,type)
{
    if(type == "START")
    {
        var control = $id("UFT.STARTTIME");
    }
    else
    {
        var control = $id("UFT.ENDTIME");
    }
    var time = control.value;
    var hours = parseInt(time.split(":")[0]);
    var minutes = time.split(":")[1];
    var newhours;
    var newminutes;
    if(operand == "PLUS")
    {
        if(minutes == "00")
        {
            newhours = hours;
            newminutes = "30";
        }
        else
        {
            if(hours == 23)
            {
                hours = -1;
            }
            newhours = hours+1;
            newminutes = "00";
        }
    }
    else
    {
        if(minutes == "00")
        {
            if(hours == 0)
            {
                hours = 24;
            }
            newhours = hours-1;
            newminutes = "30";
        }
        else
        {
            newhours = hours;
            newminutes = "00";
        }
    }
    
    //alert(operand+type+hours+minutes+"-"+newhours.toString()+newminutes);
    control.value = newhours.toString()+":"+newminutes;
}
checkAll = function()
{
    dgGuest_Invitation_c.SelectAllRowsOnPage();
}
uncheckAll = function()
{
    dgGuest_Invitation_c.UnselectAllRowsOnPage();
}